package com.jbp.service;

import com.jbp.service.impl.SendNoteMessageServiceAliImpl;
import com.jbp.service.impl.SendNoteMessageServiceHfyImpl;
import com.jbp.service.impl.SendNoteMessageServiceYtxmpl;
import com.jbp.service.impl.SendNoteMessageServiceZtmpl;
import com.jbp.utils.BeanUtil;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SendNoteMessageFactory {

    @Autowired
    private PropertyService propertyService;

    public SendNoteMessageService getSendNoteMessageService() {
        // 默认返回阿里云的实现；如果配置了短信厂商，以配置为准，支持的配置为ali, ytx, zt
        String msgProvider = propertyService.getV("msg_provider");

        if ("ali".equals(msgProvider)){
            return (SendNoteMessageService)BeanUtil.getBean(SendNoteMessageServiceAliImpl.class);
        } else if ("ytx".equals(msgProvider)) {
            return (SendNoteMessageService)BeanUtil.getBean(SendNoteMessageServiceYtxmpl.class);
        } else if ("zt".equals(msgProvider)) {
            return (SendNoteMessageService)BeanUtil.getBean(SendNoteMessageServiceZtmpl.class);
        } else if ("hfy".equals(msgProvider)) {
            return (SendNoteMessageService)BeanUtil.getBean(SendNoteMessageServiceHfyImpl.class);
        } else {
            return BeanUtil.getBean(SendNoteMessageServiceAliImpl.class);
        }
    }
}
